<?php
//ob_start("ob_gzhandler");
// list webboard's topics
//
// digiboard by digitalboom.org
// http://www.digitalboom.org
//
// Information Technology program
// Sirindhorn International Institute of Technology
// Thammasat University, Rangsit Campus
// http://www.siit.tu.ac.th
//
// authors: bact', hoho, pa+, BiGGA, MHz, kobkrit
// first created on: 2001 Jun xx
// last modified on: 2008 May 14 (fixed PHP 5 uncompatibilities)
// last modified by: kobkrit

//search by pa+
//many things by hoho
//something by BiGGA
//extended ip retrieving by MHz
//some JavaScript taken from Ying's at gats.rwth-aachen 
//PHP 5 compatabilities + user profile edit feature by kobkrit (sea)

//use session to count currently online 'guest' 
session_start();
$SID = session_id();

include("settings/config.inc.php");
include("settings/accounts.inc.php");
include("settings/forum.inc.php");
include("lib/util.inc.php");
include("lib/users_function.inc.php");
include("lib/sh.inc.php");
include("lib/list_util.inc.php");

global $DGB;

extract($_POST);
extract($_GET);

$NowTimeStamp = time();
$NowTimeStamp_Offsetted = $NowTimeStamp-($DGB["TIME_OFFSET"]*3600);

if (!isset($forum) || (@$forum < -1) || (@$forum > $DGB_FORUM["NUMBER"]))
 $forum = $DGB['DEFAULT_FORUM'];

if (empty($sortby))
 $sortby = $DGB['DEFAULT_SORT'];

if (!isset($order))
 $order = "desc";

if (empty($page) || (@$page <= 0))
 $page = 1;

if (empty($ppage) || (@$ppage <= 0) || (@$ppage > $DGB['MAX_TOPICS_PER_PAGE']))
 $ppage = $DGB['DEFAULT_TOPICS_PER_PAGE'];

// Search by Pa+ it://3
if (!isset($keyword))
 $keyword = "";

// reset the default text
if ($keyword == " search")
 $keyword = "";
 
$keyword = trim($keyword);

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$DGB["ENCODING"];?>">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="refresh" content="<?=$DGB["REFRESH_TIME"];?>">
<meta name="keywords" content="SIIT, student, community, Sirindhorn, Thammasat, TU, alumni, alumnus, forum, webboard, discussion, bbs, bulletin, university, college, school, education, Thai, Thailand, engineering, technology, science, management, network">
<meta name="description" content="Discussion board of Sirindhorn International Institute of Technology, Thammasat University, Thailand">
<link rel="shortcut icon" href="http://siit.net/files/favicon.ico" type="image/x-icon">
<link rel="alternate" type="application/rss+xml" title="SIIT.NET webboard" href="http://siit.net/webboard/feed/rss.xml">
<title><?=$DGB["WEBBOARD_NAME"];?> / <?=forum_name($forum);?></title>
<link rel="stylesheet" href="<?=$DGB["STYLESHEET"];?>" type="text/css">


<script type="text/javascript">
<!--
function reload_list_with_keyword() {
 f = document.listview.forum.options[document.listview.forum.selectedIndex].value;
 s = document.listview.sortby.options[document.listview.sortby.selectedIndex].value;
 p = document.listview.page.options[document.listview.page.selectedIndex].value;
 pp = document.listview.ppage.options[document.listview.ppage.selectedIndex].value;  
 k = document.listview.keyword.value;
 document.location.href = 'list.php?forum='+f+'&sortby='+s+'&page='+p+'&ppage='+pp+'&keyword='+k;
}

function reload_list_without_keyword() {
 f = document.listview.forum.options[document.listview.forum.selectedIndex].value;
 s = document.listview.sortby.options[document.listview.sortby.selectedIndex].value;
 pp = document.listview.ppage.options[document.listview.ppage.selectedIndex].value;

 document.location.href = 'list.php?forum='+f+'&sortby='+s+'&ppage='+pp;
}

var remote=null;
function nw(n,u,w,h,x) {
 args="width="+w+",height="+h+",resizable=yes,scrollbars=yes,status=0";
 remote=window.open(u,n,args);
 if (remote != null) {
  if (remote.opener == null)
   remote.opener = self;
 }
 if (x == 1) { return remote; }
}
// -->
</script>

</head>

<?php
$result = topiclist_prepare($forum, $sortby, $order, $page, $ppage, $keyword);
$totalpages = topiclist_total_pages();

$AlreadyLogin = 0;
//All users online (include members)
$AllGuestOnlineNum= GuestOnline($SID); 
?>

<body bgcolor="#FFFFEE">

<table width="100%" border=0 cellspacing=0 cellpadding=0>
<form name="listview">
<tr>
<td>
<!--Head-->
<table class="pHead" width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr valign="middle">
  <td align="left">
   <span><a href="<?=$DGB["HTTP_PATH"];?>"><?=$DGB["WEBBOARD_NAME"];?></a>&nbsp;/&nbsp;</span>
   <?=forum_selector($forum);?>
  </td>
  <td align="right">
   <?=date($DGB["LONG_DATETIME_FORMAT"],$NowTimeStamp_Offsetted)?>
  </td>
 </tr>
</table>

<? if ($DGB["ENABLE_ADDITIONALFORUMBAR"]) {?> 
<!-- forum bar -->
<table class="pSubHead" width="100%" border=0 cellspacing=0 cellpadding=0>
 <tr>
  <td valign="middle">
   <table class="mb" border=0 cellspacing=0 cellpadding=3>
    <tr valign="baseline">
    <td class="mbMouseOver" title="on right hand, quick link to forums. (more forums selection at the top)">forum: </td>
    <td class="mb">&nbsp;</td>
    <?=forum_list($forum,$sortby,$ppage);?>
    </tr>
   </table>
  </td>   
 </tr>
</table>
<?}?>

<!--SubHead-->
<table class="pSubHead" width="100%" border=0 cellspacing=0 cellpadding=0>
 <tr>
  <td valign="middle">
   <table class="mb" border=0 cellspacing=0 cellpadding=3>
    <tr valign="baseline">
     <td onMouseOver="this.className='mbMouseOver'; return true"
       onMouseOut="this.className='mb'; return true"
       onClick="document.location.href='postnew.php';"><a
       href="postnew.php" title="post new topic"><img src="images/mb_post.gif" alt="post new topic"
       width=16 height=16 border="0" align="bottom"></a> <a
       class="mb" href="postnew.php?forum=<?=$forum;?>" title="post new topic">post</a></td>
     <?php
      if($DGB["ENABLE_LOGIN"] == true) {
       if (isset($_COOKIE["Password"]) && isset($_COOKIE["Username"])) {
        shad2pw($_COOKIE["Password"]);
        $AlreadyLogin = CheckUser($_COOKIE["Username"], $_COOKIE["Password"]);
       }
       if($AlreadyLogin=="0") { ?>
     <td onMouseOver="this.className='mbMouseOver'; return true"
      onMouseOut="this.className='mb'; return true"
      onClick="document.location.href='login.php';"><a
      href="login.php" title="log in"><img src="images/mb_login.gif" alt="log in"
      width=16 height=16 border=0 align="bottom"></a> <a
      class="mb" href="login.php" title="log in">log in</a></td>
     <td onMouseOver="this.className='mbMouseOver'; return true"
      onMouseOut="this.className='mb'; return true"
      onClick="document.location.href='newusers.php';"><a
      href="newusers.php" title="register new screen name"><img src="images/mb_register.gif"
      alt="register new screen name" width=16 height=16 border=0 align="bottom"></a> <a
      class="mb" href="newusers.php" title="register new screen name">register</a></td>
     <? } elseif ($AlreadyLogin == "1") { ?>
     <td onMouseOver="this.className='mbMouseOver'; return true"
      onMouseOut="this.className='mb'; return true"
      onClick="document.location.href='logout.php';"><a
      href="logout.php" title="log out"><img src="images/mb_logout.gif" alt="log out"
      width=16 height=16 border=0 align="bottom"></a> <a
      class="mb" href="logout.php" title="log out">log out</a></td>
     <td onMouseOver="this.className='mbMouseOver'; return true"
      onMouseOut="this.className='mb'; return true"><a
      class="mb" href="myprofile.php" target="edit_profile" title="edit profile"><img
      src="images/mb_register.gif" alt="edit profile"
      width=16 height=16 border=0 align="bottom"></a> <a
      class="mb" href="myprofile.php" target="edit_profile" title="edit profile"><?=$_COOKIE["Username"];?></a><sup> &#174;</sup></td>
     <? } } ?>
	   <td onMouseOver="this.className='mbMouseOver'; return true"
      onMouseOut="this.className='mb'; return true"><a
      href="javascript:nw('help','html/help.html',250,300,0)" title="help / how-to / notes"><img src="images/mb_help.gif"
      alt="help" width=16 height=16 border=0 align="bottom"></a> <a
      class="mb" href="javascript:nw('help','html/help.html',250,300,0)" title="help / how-to / notes">help</a></td>
	  <td onMouseOver="this.className='mbMouseOver'; return true"
      onMouseOut="this.className='mb'; return true"
      onClick="document.location.href='members.php';"><a
      href="members.php" title="member list"><img src="images/mb_members.gif" alt="member list"
      width=16 height=16 border=0 align="bottom"></a> <a
      class="mb" href="members.php" title="member list">member list</a></td>
    </tr>
   </table>
  </td>
  <td align="right">
   <table class="mb" border=0 cellspacing=0 cellpadding=0>
    <tr valign="baseline">
     <td><img src="images/mb_sortby.gif" alt="sort by" title="sort by" width=16 height=16 align="bottom"><?=sortby_selector($sortby);?> </td>
     <td><img src="images/mb_page.gif" alt="page <?=$page;?> of <?=$totalpages;?>" title="page <?=$page;?> of <?=$totalpages;?>" width=16 height=16 align="bottom"><?=page_selector($totalpages,$page);?></td>
     <td><img src="images/mb_ppage.gif" alt="topics/page" title="topics/page" width=16 height=16 align="bottom"><?=perpage_selector($ppage, 25, 100);?> </td>
     <td><img src="images/mb_search.gif" alt="search" title="search" width=16 height=16 align="bottom"><input
     class="fmb" type="text" title="put your search keyword here, then click 'search' button"
     name="keyword" size=9  <? if (empty($keyword)) {
          echo "value=\" search\"";
          } else {
          echo "value=\"$keyword\"";
          }
     ?> onClick="javascript:if (document.listview.keyword.value == ' search') document.listview.keyword.value='';">&nbsp;<input
     class="mbbs" type="submit" value="search" title="start searching">&nbsp;</td>
    </tr>
   </table>
  </td>
 </tr>
</table>
</td>
</tr>
</form>
</table>

<!-- who's online bar -->
<table width="100%" border=0 cellspacing=0 cellpadding=0>
 <tr class="UserOnline">
  <td>&nbsp;
  <?php
  if ($keyword != '') {
   echo "search result for \"<b>$keyword</b>\"";
  }
  ?>
  </td>
  <td align="right">
  <?php
   if ($DGB["ENABLE_LOGIN"] == true) {
    // count only guests (non-members)
    $OnlyGuest = OnlyGuestNum($AllGuestOnlineNum); 
    $List = UserOnline();
    
    echo $OnlyGuest;
    if (($OnlyGuest != "") && ($List != "")) {
     echo " and ";
    }
    echo $List;
   }
  ?>&nbsp;
  </td>
 </tr>
</table>   

<table class="lsTable" width="98%" border=0 cellspacing=0 cellpadding=1 align="center">
 <thead class="lsHeader"> 
  <tr> 
   <th width="5%" class="lsHeader" title="topic id">id</th>
   <th width="4%" class="lsHeader" title="forum">forum</th>
   <th width="65%" class="lsHeader" title="topic's title">title</th>
   <th width="8%" class="lsHeader" title="time of topic's post">post</th>
   <th width="8%" class="lsHeader" title="time of last answer's post">update</th>
   <th width="5%" class="lsHeader" title="numbers of reads">read</th>
   <th width="5%" class="lsHeader" title="numbers of answers">ans</th>
  </tr>
  <tr class="lsDelim"> 
   <th colspan=7><img src="images/pixel.gif" width=1 height=1></th>
  </tr>
 </thead>
 <tbody class="lsBody"> 
  <!--STICKY TOPICS LIST-->
  <?php
   // open sticky topics list file
   $filename = "settings/stickytopics.txt";
   $line = file($filename);
   $sticky_num = sizeof($line);
   if (file_exists($filename)) {
    $fp = fopen("$filename","r");
    while ($StickyTopicID=fgets($fp,99)) {
     sticky_topiclist_print($StickyTopicID,$sticky_num);
     $sticky_num -= 1; // for changing color -- need better method
    }
    fclose($fp);
   }
  ?>
  <!--TOPICS LIST BODY-->
  <?php
   topiclist_print($result);
  ?>
 </tbody> 
 <tr class="lsDelim"> 
  <td colspan=7><img src="images/pixel.gif" width=1 height=1></td>
 </tr>
 </table>

 <!--ADDITIONAL INFO (birthday & stats)--> 
 <table class="BoardStats" width="98%" border=0 cellspacing=0 cellpadding=1 align="center">
 <tr> 
  <td align="left"> 
   <?echo $BirthDay = HappyBirthday();?>
  </td>
  <? if ($DGB["BOARD_STATS"] == true) {?>
  <td align="right">
   <a class="linkBtn2" href="stats.php" target="_blank">board stats</a> |
   feed: <a style="border: 1px solid ; margin: 0px; padding: 0px 5px; font-weight: bold; font-size: 12px; vertical-align: middle; color: white; font-family: arial,helvetica; background-color: rgb(255, 102, 0); text-decoration: none;" href="http://siit.net/webboard/feed/rss.xml" title="RSS 2.0 Syndication">RSS</a>
  </td>
  <?}?>
 </tr>
</table>

<?php
 include("html/footer.html");
?>
</body>
</html>
